﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ITProject.Domain.Entities;

namespace ITProject.WebUI.Models.Project
{
    public class ProjectFeatureViewModel
    {
        public string Name { get; set; }
        public string Receiver { get; set; }
        public bool IsToTeam { get; set; }
        public string Status { get; set; }
        public string PlannedEndDate { get; set; }
        public string StartDate { get; set; }
        public string Description { get; set; }
        public string Priority { get; set; }
        public StatusChangeViewModel[] FeatureStatusChanges { get; set; }

        public static ProjectFeatureViewModel[] Convert(Feature[] features, string[] receivers, StatusChange[][] statusChanges, string[][] statusChangesUserNames)
        {
            ProjectFeatureViewModel[] vmTab = new ProjectFeatureViewModel[features.Length];
            for (int i = 0; i < features.Length; i++)
            {
                vmTab[i] = new ProjectFeatureViewModel();
                vmTab[i].Name = features[i].Name;
                vmTab[i].Description = features[i].Description;
                vmTab[i].PlannedEndDate = features[i].PlannedEndDate.ToLongDateString();
                vmTab[i].StartDate = features[i].StartDate.ToLongDateString();
                vmTab[i].Priority = PriorityViewModel.ConvertFromByte(features[i].Priority);
                vmTab[i].Status = StatusName.ConvertFromByte(features[i].Status);
                vmTab[i].Receiver = receivers[i];
                vmTab[i].IsToTeam = features[i].IsToTeam;
                vmTab[i].FeatureStatusChanges = new StatusChangeViewModel[statusChanges[i].Length];
                for (int j = 0; j < statusChanges[i].Length; j++)
                    vmTab[i].FeatureStatusChanges[j] = StatusChangeViewModel.Convert(statusChanges[i][j], statusChangesUserNames[i][j]);
            }
            return vmTab;
        }
    }
}